package com.qezhhnjy.mall.coupon.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.coupon.SkuLadder;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.coupon.service.SkuLadderService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 商品阶梯价格 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "商品阶梯价格接口")
@Slf4j
@RequestMapping("/sku-ladder")
public class SkuLadderController {
    @Resource
    private SkuLadderService skuLadderService;

    @GetMapping("/get")
    @Operation(summary = "根据id获取商品阶梯价格信息")
    public BaseResult<SkuLadder> get(Long id) {
        SkuLadder skuLadder = skuLadderService.getById(id);
        return BaseResult.success(skuLadder);
    }

    @PostMapping("/save")
    @Operation(summary = "新增商品阶梯价格信息")
    public BaseResult<SkuLadder> save(@RequestBody SkuLadder skuLadder) {
        skuLadderService.save(skuLadder);
        return BaseResult.success(skuLadder);
    }

    @PutMapping("/update")
    @Operation(summary = "更新商品阶梯价格信息")
    public BaseResult<SkuLadder> update(@RequestBody SkuLadder skuLadder) {
        skuLadderService.updateById(skuLadder);
        return BaseResult.success(skuLadder);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取商品阶梯价格信息")
    public BaseResult<Page<SkuLadder>> page(@RequestBody Page<SkuLadder> page) {
        skuLadderService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除商品阶梯价格信息")
    public BaseResult<Long> delete(Long id) {
        skuLadderService.removeById(id);
        return BaseResult.success(id);
    }
}

